﻿Imports System.IO

Public Class formsearch
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call.

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents cboDirectory As System.Windows.Forms.ComboBox
    Friend WithEvents txtFile As System.Windows.Forms.TextBox
    Friend WithEvents lstFilesFound As System.Windows.Forms.ListBox
    Friend WithEvents lblDirectory As System.Windows.Forms.Label
    Friend WithEvents lblFile As System.Windows.Forms.Label
    Friend WithEvents btnSearch As System.Windows.Forms.Button
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer.
    'You can use the Windows Form Designer to modify it; however, do not
    'use the code editor to modify it.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(formsearch))
        Me.btnSearch = New System.Windows.Forms.Button()
        Me.lblFile = New System.Windows.Forms.Label()
        Me.cboDirectory = New System.Windows.Forms.ComboBox()
        Me.txtFile = New System.Windows.Forms.TextBox()
        Me.lstFilesFound = New System.Windows.Forms.ListBox()
        Me.lblDirectory = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        '
        'btnSearch
        '
        Me.btnSearch.Location = New System.Drawing.Point(608, 248)
        Me.btnSearch.Name = "btnSearch"
        Me.btnSearch.Size = New System.Drawing.Size(75, 23)
        Me.btnSearch.TabIndex = 0
        Me.btnSearch.Text = "Search"
        '
        'lblFile
        '
        Me.lblFile.Location = New System.Drawing.Point(8, 16)
        Me.lblFile.Name = "lblFile"
        Me.lblFile.Size = New System.Drawing.Size(144, 16)
        Me.lblFile.TabIndex = 5
        Me.lblFile.Text = "Search for files containing:"
        '
        'cboDirectory
        '
        Me.cboDirectory.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        Me.cboDirectory.DropDownWidth = 112
        Me.cboDirectory.Location = New System.Drawing.Point(8, 128)
        Me.cboDirectory.Name = "cboDirectory"
        Me.cboDirectory.Size = New System.Drawing.Size(120, 21)
        Me.cboDirectory.TabIndex = 2
        Me.cboDirectory.Text = "ComboBox1"
        '
        'txtFile
        '
        Me.txtFile.Location = New System.Drawing.Point(8, 40)
        Me.txtFile.Name = "txtFile"
        Me.txtFile.Size = New System.Drawing.Size(120, 20)
        Me.txtFile.TabIndex = 4
        Me.txtFile.Text = "*.exe"
        '
        'lstFilesFound
        '
        Me.lstFilesFound.Location = New System.Drawing.Point(152, 8)
        Me.lstFilesFound.Name = "lstFilesFound"
        Me.lstFilesFound.Size = New System.Drawing.Size(528, 225)
        Me.lstFilesFound.TabIndex = 1
        '
        'lblDirectory
        '
        Me.lblDirectory.Location = New System.Drawing.Point(8, 96)
        Me.lblDirectory.Name = "lblDirectory"
        Me.lblDirectory.Size = New System.Drawing.Size(120, 23)
        Me.lblDirectory.TabIndex = 3
        Me.lblDirectory.Text = "Look In:"
        '
        'formsearch
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(688, 273)
        Me.Controls.Add(Me.lblFile)
        Me.Controls.Add(Me.txtFile)
        Me.Controls.Add(Me.lblDirectory)
        Me.Controls.Add(Me.cboDirectory)
        Me.Controls.Add(Me.lstFilesFound)
        Me.Controls.Add(Me.btnSearch)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "formsearch"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Search Tool"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub btnSearch_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnSearch.Click
        lstFilesFound.Items.Clear()
        txtFile.Enabled = False
        cboDirectory.Enabled = False
        btnSearch.Text = "Searching..."
        Me.Cursor = Cursors.WaitCursor
        Application.DoEvents()
        DirSearch(cboDirectory.Text)
        btnSearch.Text = "Search"
        Me.Cursor = Cursors.Default
        txtFile.Enabled = True
        cboDirectory.Enabled = True
    End Sub

    Sub DirSearch(ByVal sDir As String)
        Dim d As String
        Dim f As String

        Try
            For Each d In Directory.GetDirectories(sDir)
                For Each f In Directory.GetFiles(d, txtFile.Text)
                    lstFilesFound.Items.Add(f)
                Next
                DirSearch(d)
            Next
        Catch excpt As System.Exception
            Debug.WriteLine(excpt.Message)
        End Try
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles MyBase.Load
        Dim s As String
        cboDirectory.Items.Clear()
        For Each s In Directory.GetLogicalDrives()
            cboDirectory.Items.Add(s)
        Next
        cboDirectory.Text = "C:\"
    End Sub

    Private Sub cboDirectory_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboDirectory.SelectedIndexChanged

    End Sub
End Class
